package org.egomsl.mw;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.TestMiniDFSCluster;
import org.apache.thrift.transport.TTransportException;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;

public abstract class ABaseTestBase {
    protected MiniDFSCluster dfsCluster;
    protected FileSystem fs;
    protected Path testPath;

    @Before
    public void setup() throws IOException, InterruptedException {
        Configuration conf = new Configuration();
        if (System.getProperty("test.build.data") == null) {
            System.setProperty("test.build.data", "/tmp/abase");
        }
        testPath = new Path(System.getProperty("test.build.data"));

        /*
        dfsCluster = new MiniDFSCluster(conf, 1, true, null);
        fs = dfsCluster.getFileSystem();
        */

        //raw filesystem support append operation
        fs = ((LocalFileSystem)LocalFileSystem.get(conf)).getRawFileSystem();
    }

    @After
    public void shutdown() {
        if(dfsCluster != null) dfsCluster.shutdown();
    }
}
